Support TopoUSA 6.0 routes.
authorrobertl <robertl>
Tue, 20 Nov 2007 04:30:43 +0000 (04:30 +0000)
committerrobertl <robertl>
Tue, 20 Nov 2007 04:30:43 +0000 (04:30 +0000)
saroute.c

index cd9648cf6bb9fb91fa8ffad273be3f6ca894f3d0..b18261c21a1b768e7b34e35d9d932a5635f0a26e 100644 (file)
--- a/saroute.c
+++ b/saroute.c
@@ -215,23 +215,36 @@ my_read(void)
                        wpt_tmp->latitude = lat;
                        wpt_tmp->longitude = -lon;
                        if ( control ) {
-                           int addrlen = le_read16((short *)
-                               (((char *)record)+18));
-                           int cmtlen = le_read16((short *)
-                               (((char *)record)+20+addrlen));
-                           wpt_tmp->notes = (char *)xmalloc(cmtlen+1);
-                           wpt_tmp->shortname = (char *)xmalloc(addrlen+1);
-                           wpt_tmp->notes[cmtlen] = '\0';
+                           int obase, addrlen, cmtlen;
+
+                           /* Somewhere around TopoUSA 6.0, these moved  */
+                           /* This block also seems to get miscompiled 
+                            * at -O0 on Linux.  I tried rewriting it to
+                            * reduce/eliminate some of the really funky
+                            * pointer math and casting that was here.
+                            */
+                           if (version >= 11) {
+                               obase = 20;
+                           } else {
+                               obase = 18;
+                           }
+
+                           addrlen = le_read16(&record[obase]);
+                           cmtlen = le_read16(&record[obase+2+addrlen]);
+
+                           wpt_tmp->shortname = xmalloc(addrlen+1);
                            wpt_tmp->shortname[addrlen]='\0';
+                           wpt_tmp->notes = xmalloc(cmtlen+1);
+                           wpt_tmp->notes[cmtlen] = '\0';
                            memcpy(wpt_tmp->notes, 
-                                  ((char *)record)+22+addrlen,
+                                  record+obase+4+addrlen,
                                   cmtlen );
                            memcpy(wpt_tmp->shortname,
-                                  ((char *)record)+20,
+                                  record+obase+2,
                                   addrlen );
                        }
                        else {
-                           wpt_tmp->shortname = (char *) xmalloc(7);
+                           wpt_tmp->shortname = xmalloc(7);
                            sprintf( wpt_tmp->shortname, "\\%5.5x", serial++ );
                        }
                        if ( control == 2 ) {